var network = require("../../../utils/network.js")
Page({
	data: {
    sixty:"",
    display1: "block",
    display2: "none",
		tel: '',
		password: '',
    hidden:true,
    imgurl: "../../../images/iconImgs/logo.png"
	},
	bindTelInput: function(e) {
		this.setData({tel: e.detail.value})
	},
  bindPasswordInput:function(e){
    this.setData({ smsCode : e.detail.value })
  },
  toVerification:function(){
    if ((/^1(3|4|5|7|8)\d{9}$/.test(this.data.tel))){
      var that = this
      var phone = that.data.tel
      var data = {}
      data.phone= phone
      network.postData(
        "https://api.hsb1234.com/common/v1/smsCode",
        data,
        function (res) {
          var message = res.data.message
          console.log(message)
         },
        function (res) { }
      )
      wx.showToast({
        title: '请留意手机短信',
        icon: 'success',
        duration: 1000
      })
     
      that.setData({
        display1: "none",
        display2: "block"
      })
      var seconds = 60
      var clock = setInterval(doLoop, 1000)
      function doLoop() {
        if (seconds > 0) {
          seconds--;
          that.setData({
            sixty: seconds + "秒后可继续发送",
          })
        } else {
          clearInterval(clock)
          seconds = 60
          that.setData({
            sixty: "",
            display1: "block",
            display2: "none",
          })
        }
      }
    }else{
      wx.showToast({
        title: '号码格式不正确',
        icon: 'fail',
        duration: 1000
      })
    }
  },
  lookDeal:function(){
    this.setData({
      display:"block"
    })
  },
  shut:function(){
    this.setData({
      display: "none"
    })
  },
  readed:function(){
    this.setData({
      hidden:true
    })
  },
  lookDeal:function(){
    this.setData({
      hidden:false
    })
  },
	login: function(e) {
    var data = {}
    data.smsCode = this.data.smsCode 
    data.phone = this.data.tel 
    data.openid = wx.getStorageSync("openid")
    data.password =""
		wx.showToast({title: '请求中', icon: 'loading', duration: 5000});
		//网络请求开始
    network.postData(
      "https://api.hsb1234.com/userc/v1/login",
      data,
      function(res){
        wx.hideToast();
        var resdata = res.data.data
        var uid = resdata.uid
        var token = resdata.token 
        var name = resdata.name
        wx.setStorageSync("uid", uid)
        wx.setStorageSync("token", token)
          wx.switchTab({
            url: '../../index/index',
            success: function () {
              console.log("called switchtab.");
            }
          });
      },
      function(){}
    )
	}
})
